import Vue from 'vue';
import { checkBrowser } from '@/lib/checkBrowser.js';

import 'normalize.css/normalize.css'; // A modern alternative to CSS resets

global.ENVIR = 'game';

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css'; // lang i18n
import i18n from '@/lib/lang/index';
import VueCropper from 'vue-cropper';
import '@/lib/oidc';

import '@/styles/index.scss'; // 公共样式
import '@/styles/spacing.scss'; // gl的公共样式
import '@/styles/global.scss'; // gl的公共样式
import '@/assets/iconfont/iconfont.css';

import App from './App';
import store from '@/extend/store';
import router from '@/extend/router/mycenter/index';
import * as filters from '@/lib/filter'; // 全局过滤器

import '@/assets/icons/index'; // icon
import { translateByCode } from '@/lib/getTransData';

import { initBaidu } from '../baidu.js';

// 百度统计
if (process.env.VUE_APP_ISUSE_BDTJ && process.env.VUE_APP_ISUSE_BDTJ !== 'false') {
  initBaidu();
}

Vue.use(VueCropper);

// 全局插件
import Login from '@/plugin/Login';
Vue.use(Login);
import ForgetPassword from '@/plugin/ForgetPassword';
Vue.use(ForgetPassword);
import Register from '@/plugin/Register';
Vue.use(Register);
import ShowAvatar from '@/plugin/ShowAvatar';
Vue.use(ShowAvatar);

// 设置全局函数
store.dispatch('app/setTitle', translateByCode(process.env.VUE_APP_TITLE_GAME));

// 兼容性解决
if (!window.location.origin) {
  window.location.origin =
    window.location.protocol +
    '//' +
    window.location.hostname +
    (window.location.port ? ':' + window.location.port : '');
}

// 设置elementUi语言
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value)
});

// 注册全局过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});

Vue.config.productionTip = false;

// 校验浏览器版本
const browserIsSupport = checkBrowser();
if (browserIsSupport) {
  new Vue({
    el: '#app',
    router,
    store,
    i18n,
    data() {
      return {
        refreshEvent: new Vue() // 根据父级路由的变化触发子路由的更新
      };
    },
    render: h => h(App)
  });
}
